#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2) {
        int pos = 0;
        for (int i = 0; i < arr2.size(); i++)
        {
            for (int j = pos; j < arr1.size(); j++)
            {
                if (arr1[j] == arr2[i])
                {
                    swap(arr1[pos++], arr1[j]);
                }
            }
        }
        vector<int>::iterator it = arr1.begin() + pos;
        sort(it, arr1.end());

        return arr1;
    }
};